/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved. distributed with this file and
 * available online at
 */
package com.lap.auth.adapter.driving.query.msg.repository;

import com.lap.auth.adapter.driving.query.msg.MsgTemplateQueryConverter;
import com.lap.auth.adapter.driving.query.msg.mapper.MsgTemplateQueryMapper;
import com.lap.auth.adapter.driving.query.msg.po.MsgTemplateQueryPo;
import com.lap.auth.application.msg.dto.MsgTemplateDto;
import com.lap.auth.application.msg.dto.QueryMsgTemplatePageQuery;
import com.lap.auth.application.msg.repository.MsgTemplateQueryRepository;
import com.lap.framework.dto.page.PageResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class MsgTemplateQueryRepositoryImpl implements MsgTemplateQueryRepository {

  private final MsgTemplateQueryConverter converter;
  private final MsgTemplateQueryMapper msgTemplateQueryMapper;

  @Override
  public PageResponse<MsgTemplateDto> findByConditionPaged(QueryMsgTemplatePageQuery query) {
    long count = msgTemplateQueryMapper.countPageByCondition(query);
    if (count == 0L) {
      return PageResponse.ok(count);
    }
    List<MsgTemplateQueryPo> list = msgTemplateQueryMapper.selectPageByCondition(query);
    return PageResponse.ok(converter.toDtoList(list), count);
  }
}
